import tkinter as tk
from GUI.FileSenderGUI import *

class DeviceListGui:
    def __init__(self,geometry):
        self.win = tk.Tk()
        self.win.geometry(geometry)
        self.deviceList = tk.Listbox(self.win,font=("Helvetica",20))
        self.deviceList.place(x=50,y=10,height=500,width=700)
        self.connectButton = tk.Button(self.win,text="发送",width=20,height=2,command=self.jumptoSenderGUI)
        self.connectButton.place(x=50,y=550)
        # 列表框绑定函数
        self.deviceList.bind('<<ListboxSelect>>', self.listbox_click)
        # 选中的目标主机信息
        self.selectaddr = {}

    

    
    # 列表框点击事件绑定函数
    def listbox_click(self,event):
        # 向文本区光标处插入列表框当前选中文本
        res = self.deviceList.get(self.deviceList.curselection())
        # print(eval(res))
        self.selectaddr['username']=eval(res)[0]
        self.selectaddr['addr']=eval(res)[1]
        print(self.selectaddr)

    def jumptoSenderGUI(self):
        newFileSenderGUI = FileSenderGUI("800x600",self.selectaddr)
        newFileSenderGUI.MainLoop()


    def MainLoop(self):
        self.win.mainloop()


if __name__ == "__main__":
    myDeviceListGui = DeviceListGui("800x600")